extends Action

@export var attack := 7

func performAction() -> void:
	if !enemy or !target: return

	# 敌人的行为动画
	var tween := create_tween().set_trans(Tween.TRANS_QUINT)
	var start := enemy.global_position
	var end := target.global_position + Vector2.RIGHT * 32
	var damage: Damage = Damage.new()
	damage.amount = attack
	damage.sound = self.sound

	tween.tween_property(enemy, "global_position", end, 0.4)
	tween.tween_callback(damage.execute.bind([target] as Array[Node]))
	# tween间隔0.25s执行
	tween.tween_interval(0.25)
	tween.tween_property(enemy, "global_position", start, 0.4)

	tween.finished.connect(
		func(): Events.actionCompleted.emit(enemy)
	)
